package com.netty.esc.common.enums;

/**
 * @Author Dyt
 * @DATE 2021/11/2
 * @DESC
 */
public enum WSProtocolTypeEM {

    //系统 - 01开头
    PING_PROT("ping", "011"),
    PONG_PROT("pong", "012"),
    ERROR_UNKNOWN("通用异常", "019"),

    //消息类 - 02开头
    MSG("消息","021"),
    PERSON_MSG("私聊消息","022"),
    PEOPLE_MSG("群聊消息","023"),

    //操作类 - 03开头
    ONLINE("用户上线","030"),
    FRIEND_ADD("新的好友请求","031"),
    FRIEND_ONLINE("好友上线提醒","032"),
    FRIEND_DOWN("好友下线提醒","033"),

    UNKNOWN("未知协议", "000"),
    ;

    private final String desc;
    private final String code;

    WSProtocolTypeEM(String desc, String code) {
        this.desc = desc;
        this.code = code;
    }

    public String desc() {
        return desc;
    }

    public String code() {
        return code;
    }

    /*
     * 匹配操作码
     * */
    public static WSProtocolTypeEM matchType(String code) {
        for (WSProtocolTypeEM protocolType : WSProtocolTypeEM.values()) {
            if (protocolType.code().equals(code)) {
                return protocolType;
            }
        }
        return WSProtocolTypeEM.UNKNOWN;
    }
}
